package it.polimi.travelDreamEJB.web.beans;

import java.util.ArrayList;
import java.util.List;

import it.polimi.travelDreamEJB.basicproductmanagement.BasicProductMgr;
import it.polimi.travelDreamEJB.basicproductmanagement.dto.ExcursionDTO;
import it.polimi.travelDreamEJB.basicproductmanagement.dto.HotelDTO;
import it.polimi.travelDreamEJB.basicproductmanagement.dto.SearchExcursionDTO;
import it.polimi.travelDreamEJB.basicproductmanagement.dto.SearchHotelDTO;
import it.polimi.travelDreamEJB.defaultpacketmanagement.DefaultPacketMgr;
import it.polimi.travelDreamEJB.defaultpacketmanagement.dto.DefaultPacketDTO;
import it.polimi.travelDreamEJB.defaultpacketmanagement.dto.SearchDefaultPacketDTO;
import it.polimi.travelDreamEJB.usermanagement.UserMgr;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.primefaces.event.RowEditEvent;
import org.primefaces.model.SelectableDataModel;

@ManagedBean(name = "defaultPacketBean")
@ViewScoped
public class DefaultPacketBean {

	@EJB
	private DefaultPacketMgr dpm;

	@EJB
	private UserMgr user;

	@EJB
	private BasicProductMgr bpm;

	private DefaultPacketDTO defaultPacket;

	private List<DefaultPacketDTO> defaultPacketList;

	private List<String> cities;

	private String destinationSelected;
	private String hotelName ="";
	private String creatorName ="";

	private HotelDTO hotel;
	private List<HotelDTO> hotelList;

	private ExcursionDTO excursion;
	private List<ExcursionDTO> excursionList;
	private List<ExcursionDTO> excursions;

	public DefaultPacketBean() {

		// cities= bpm.possibleCities();
		cities = new ArrayList<String>();
		// cities.addAll(bpm.possibleCities());
		/*
		 * cities = new ArrayList<String>(); cities.add("Pescara");
		 * cities.add("New York");
		 */
		hotel = new HotelDTO();
		hotel.setStars(1);
		defaultPacket = new DefaultPacketDTO();
	}

	public DefaultPacketDTO getDefaultPacket() {
		return defaultPacket;
	}

	public void setDefaultPacket(DefaultPacketDTO defaultPacket) {
		this.defaultPacket = defaultPacket;
	}

	public List<DefaultPacketDTO> getDefaultPacketList() {
		return defaultPacketList;
	}

	public void setDefaultPacketList(List<DefaultPacketDTO> defaultPacketList) {
		this.defaultPacketList = defaultPacketList;
	}

	public String getDestinationSelected() {
		return destinationSelected;
	}

	public void setDestinationSelected(String destinationSelected) {
		this.destinationSelected = destinationSelected;
	}

	public List<String> getCities() {
		return cities;
	}

	public void setCities(List<String> cities) {
		this.cities = cities;
	}

	public String save() {
		defaultPacket.setEmployee(user.getUserDTO());
		defaultPacket.setHotel(hotel);
		defaultPacket.setExcursions(excursions);
		dpm.save_default_packet(defaultPacket);
		return "packet?faces-redirect=true";
	}

	public void button() {

		cities.clear();
		cities.addAll(bpm.possibleCities());

	}

	public void find() {
		SearchDefaultPacketDTO searchDefaultPacket = new SearchDefaultPacketDTO();
		searchDefaultPacket.getHotel().setDestination(destinationSelected);
		searchDefaultPacket.getHotel().setName(hotelName);
		searchDefaultPacket.getUser().setEmail(creatorName);
		defaultPacketList = dpm.findDefaultPacket(searchDefaultPacket);
	}

	public String delete() {

		dpm.delete_default_packet(defaultPacket);
		return "packet?faces-redirect=true";

	}

	public void findBasicProducts() {
		if ( destinationSelected.equals("") ){
			return;
		}
		SearchHotelDTO searchHotel = new SearchHotelDTO();
		SearchExcursionDTO searchExcursion = new SearchExcursionDTO();
		hotel = new HotelDTO();
		excursions.clear();
		searchHotel.setDestination(destinationSelected);
		hotelList = bpm.findHotel(searchHotel);
		searchExcursion.setDestination(destinationSelected);
		excursionList = bpm.findExcursion(searchExcursion);
	}

	public List<HotelDTO> getHotelList() {
		return hotelList;
	}

	public void setHotelList(List<HotelDTO> hotelList) {
		this.hotelList = hotelList;
	}

	public HotelDTO getHotel() {
		return hotel;
	}

	public void setHotel(HotelDTO hotel) {
		this.hotel = hotel;
	}

	public List<ExcursionDTO> getExcursionList() {
		return excursionList;
	}

	public void setExcursionList(List<ExcursionDTO> excursionList) {
		this.excursionList = excursionList;
	}

	public ExcursionDTO getExcursion() {
		return excursion;
	}

	public void setExcursion(ExcursionDTO excursion) {
		this.excursion = excursion;
	}

	public List<ExcursionDTO> getExcursions() {
		return excursions;
	}

	public void setExcursions(List<ExcursionDTO> excursions) {
		this.excursions = excursions;
	}

	
	public String getHotelName() {
		return hotelName;
	}

	
	public void setHotelName(String hotelName) {
		this.hotelName = hotelName;
	}


	public String getCreatorName() {
		return creatorName;
	}

	
	public void setCreatorName(String creatorName) {
		this.creatorName = creatorName;
	}

	
	}
